package com.youyi.yyfilepickerlibrary.core.model;

import android.content.ContentUris;
import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import com.youyi.yyfilepickerlibrary.core.util.FileUtils;
import com.youyi.yyfilepickerlibrary.core.util.MimeType;
import com.youyi.yyfilepickerlibrary.core.util.PathUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class EssFile implements Parcelable {
    public static final int CAPTURE = 0;
    public static final Creator<EssFile> CREATOR = new Creator<EssFile>() {
        /* class com.youyi.yyfilepickerlibrary.core.model.EssFile.AnonymousClass1 */

        @Override // android.os.Parcelable.Creator
        public EssFile createFromParcel(Parcel parcel) {
            return new EssFile(parcel);
        }

        @Override // android.os.Parcelable.Creator
        public EssFile[] newArray(int i) {
            return new EssFile[i];
        }
    };
    public static final int MEDIA = 1;
    private String childFileCount;
    private String childFolderCount;
    private boolean isChecked;
    private boolean isDirectory;
    private boolean isExits;
    private boolean isFile;
    private int itemType;
    private String mFileName;
    private String mFilePath;
    private String mimeType;
    private Uri uri;

    public int describeContents() {
        return 0;
    }

    protected EssFile(Parcel parcel) {
        this.childFolderCount = "加载中";
        this.childFileCount = "加载中";
        boolean z = false;
        this.isChecked = false;
        this.isExits = false;
        this.isDirectory = false;
        this.isFile = false;
        this.itemType = 1;
        this.mFilePath = parcel.readString();
        this.mimeType = parcel.readString();
        this.childFolderCount = parcel.readString();
        this.childFileCount = parcel.readString();
        this.isChecked = parcel.readByte() != 0;
        this.isExits = parcel.readByte() != 0;
        this.isDirectory = parcel.readByte() != 0;
        this.isFile = parcel.readByte() != 0 ? true : z;
        this.mFileName = parcel.readString();
        this.uri = (Uri) parcel.readParcelable(Uri.class.getClassLoader());
        this.itemType = parcel.readInt();
    }

    public boolean isChecked() {
        return this.isChecked;
    }

    public void setChecked(boolean z) {
        this.isChecked = z;
    }

    public EssFile(String str) {
        this.childFolderCount = "加载中";
        this.childFileCount = "加载中";
        this.isChecked = false;
        this.isExits = false;
        this.isDirectory = false;
        this.isFile = false;
        this.itemType = 1;
        this.mFilePath = str;
        File file = new File(this.mFilePath);
        if (file.exists()) {
            this.isExits = true;
            this.isDirectory = file.isDirectory();
            this.isFile = file.isFile();
            this.mFileName = file.getName();
        }
        this.mimeType = FileUtils.getMimeType(this.mFilePath);
    }

    public EssFile(File file) {
        this.childFolderCount = "加载中";
        this.childFileCount = "加载中";
        this.isChecked = false;
        this.isExits = false;
        this.isDirectory = false;
        this.isFile = false;
        this.itemType = 1;
        this.mFilePath = file.getAbsolutePath();
        if (file.exists()) {
            this.isExits = true;
            this.isDirectory = file.isDirectory();
            this.isFile = file.isFile();
        }
        this.mimeType = FileUtils.getMimeType(file.getAbsolutePath());
    }

    public EssFile(long j, String str) {
        Uri uri2;
        this.childFolderCount = "加载中";
        this.childFileCount = "加载中";
        this.isChecked = false;
        this.isExits = false;
        this.isDirectory = false;
        this.isFile = false;
        this.itemType = 1;
        this.mimeType = str;
        if (isImage()) {
            uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        } else if (isVideo()) {
            uri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        } else {
            uri2 = MediaStore.Files.getContentUri("external");
        }
        this.uri = ContentUris.withAppendedId(uri2, j);
    }

    public Uri getUri() {
        return this.uri;
    }

    public boolean isExits() {
        return this.isExits;
    }

    public String getMimeType() {
        return this.mimeType;
    }

    public void setMimeType(String str) {
        this.mimeType = str;
    }

    public String getChildFolderCount() {
        return this.childFolderCount;
    }

    public void setChildFolderCount(String str) {
        this.childFolderCount = str;
    }

    public String getChildFileCount() {
        return this.childFileCount;
    }

    public void setChildFileCount(String str) {
        this.childFileCount = str;
    }

    public void setChildCounts(String str, String str2) {
        this.childFileCount = str;
        this.childFolderCount = str2;
    }

    public File getFile() {
        return new File(this.mFilePath);
    }

    public String getName() {
        return new File(this.mFilePath).getName();
    }

    public boolean isDirectory() {
        return this.isDirectory;
    }

    public boolean isFile() {
        return this.isFile;
    }

    public String getAbsolutePath() {
        return this.mFilePath;
    }

    public static List<EssFile> getEssFileList(List<File> list) {
        ArrayList arrayList = new ArrayList();
        for (File file : list) {
            arrayList.add(new EssFile(file));
        }
        return arrayList;
    }

    public static ArrayList<EssFile> getEssFileList(Context context, Set<EssFile> set) {
        ArrayList<EssFile> arrayList = new ArrayList<>();
        for (EssFile essFile : set) {
            essFile.mFilePath = PathUtils.getPath(context, essFile.uri);
            arrayList.add(essFile);
        }
        return arrayList;
    }

    public static ArrayList<String> getFilePathList(ArrayList<EssFile> arrayList) {
        ArrayList<String> arrayList2 = new ArrayList<>();
        Iterator<EssFile> it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(it.next().getAbsolutePath());
        }
        return arrayList2;
    }

    public String toString() {
        return "EssFile{mFilePath='" + this.mFilePath + '\'' + ", mimeType='" + this.mimeType + '\'' + ", mFileName='" + this.mFileName + '\'' + '}';
    }

    public boolean isImage() {
        String str = this.mimeType;
        if (str == null) {
            return false;
        }
        if (str.equals(MimeType.JPEG.toString()) || this.mimeType.equals(MimeType.PNG.toString()) || this.mimeType.equals(MimeType.GIF.toString()) || this.mimeType.equals(MimeType.BMP.toString()) || this.mimeType.equals(MimeType.WEBP.toString())) {
            return true;
        }
        return false;
    }

    public boolean isGif() {
        String str = this.mimeType;
        if (str == null) {
            return false;
        }
        return str.equals(MimeType.GIF.toString());
    }

    public boolean isVideo() {
        String str = this.mimeType;
        if (str == null) {
            return false;
        }
        if (str.equals(MimeType.MPEG.toString()) || this.mimeType.equals(MimeType.MP4.toString()) || this.mimeType.equals(MimeType.QUICKTIME.toString()) || this.mimeType.equals(MimeType.THREEGPP.toString()) || this.mimeType.equals(MimeType.THREEGPP2.toString()) || this.mimeType.equals(MimeType.MKV.toString()) || this.mimeType.equals(MimeType.WEBM.toString()) || this.mimeType.equals(MimeType.TS.toString()) || this.mimeType.equals(MimeType.AVI.toString())) {
            return true;
        }
        return false;
    }

    public void setItemType(int i) {
        this.itemType = i;
    }

    public int getItemType() {
        return this.itemType;
    }

    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.mFilePath);
        parcel.writeString(this.mimeType);
        parcel.writeString(this.childFolderCount);
        parcel.writeString(this.childFileCount);
        parcel.writeByte(this.isChecked ? (byte) 1 : 0);
        parcel.writeByte(this.isExits ? (byte) 1 : 0);
        parcel.writeByte(this.isDirectory ? (byte) 1 : 0);
        parcel.writeByte(this.isFile ? (byte) 1 : 0);
        parcel.writeString(this.mFileName);
        parcel.writeParcelable(this.uri, i);
        parcel.writeInt(this.itemType);
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof EssFile)) {
            return false;
        }
        EssFile essFile = (EssFile) obj;
        Uri uri2 = this.uri;
        if (uri2 == null) {
            return this.mFilePath.equalsIgnoreCase(essFile.getAbsolutePath());
        }
        return uri2.equals(essFile.getUri());
    }

    public int hashCode() {
        String str = this.mFilePath;
        int i = 0;
        int hashCode = (str != null ? str.hashCode() : 0) * 31;
        Uri uri2 = this.uri;
        if (uri2 != null) {
            i = uri2.hashCode();
        }
        return ((hashCode + i) * 31) + this.itemType;
    }
}
